//
//  CustomerServiceCenter.m
//  XJMCustomer
//
//  Created by Mr.hu on 2017/10/25.
//  Copyright © 2017年 Mr.hu. All rights reserved.
//

#import "CustomerServiceCenter.h"

@interface CustomerServiceCenter ()
@property (weak, nonatomic) IBOutlet UILabel *Technician_nameLab;
@property (weak, nonatomic) IBOutlet UIImageView *Technician_Headimage; //用户头像
@property (weak, nonatomic) IBOutlet UILabel *Company_MailBox; //公司邮箱
@property (weak, nonatomic) IBOutlet UILabel *Company_Service;
@property (weak, nonatomic) IBOutlet UIButton *Company_Telephone;
@property (weak, nonatomic) IBOutlet UIImageView *Company_Banner; //顶部图片

@property (nonatomic,strong)  NSDictionary * customerDict;

@end

@implementation CustomerServiceCenter

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationController setNavigationBarHidden:NO];
    self.title = @"客服中心";
    
    AFHTTPSessionManager * sessionmanager = [[AFHTTPSessionManager alloc]init];
    //申明返回来的结果是二进制类型
    sessionmanager.responseSerializer = [AFHTTPResponseSerializer serializer];
    //如果报接受类型不一致，请替换一致text/html  或者 text/plain
    sessionmanager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain", nil];
    //设置请求超时时间
    [sessionmanager.requestSerializer setTimeoutInterval:30.0];
  
    [sessionmanager GET:@"http://api.xijiaomo.com/tech.php/v2/Notice/techer_about" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                
                NSString * friendstg =[[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
                NSData * frienddata =[friendstg dataUsingEncoding:NSUTF8StringEncoding];
                NSDictionary * frienddict = [NSJSONSerialization JSONObjectWithData:frienddata options:NSJSONReadingMutableContainers error:nil];
            
            self.customerDict =frienddict[@"data"];
            self.Company_MailBox.text = self.customerDict[@"kf_email"];
            self.Company_Service.text = [NSString stringWithFormat:@"QQ:%@",self.customerDict[@"kf_qq"]];
//            [self.Company_Telephone setTitle:self.customerDict[@"company_phone"] forState:UIControlStateNormal];
//            NSString * headstr = [[NSString stringWithFormat:@"%@",[TechSimple registerpass].User_Headimage]stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
            [self.Technician_Headimage sd_setImageWithURL:[NSURL URLWithString:[TechSimple registerpass].User_Headimage] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            self.Technician_Headimage.layer.cornerRadius = 30.5;
            self.Technician_Headimage.layer.masksToBounds = YES;
        
        if ([XJToolClass getUserDic][@"truename"] == nil) {
            self.Technician_nameLab.text = [NSString stringWithFormat:@"亲 您好"];
        }else{
            self.Technician_nameLab.text = [NSString stringWithFormat:@"%@ 您好",[XJToolClass getUserDic][@"truename"]];
        }
        
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                
        }];
}

- (IBAction)CustomerCenterMeth:(id)sender {
    
    NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@",self.customerDict[@"company_phone"]];
    CGFloat version = [[[UIDevice currentDevice]systemVersion]floatValue];
    if (version >= 10.0) {
        /// 大于等于10.0系统使用此openURL方法
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone] options:@{} completionHandler:nil];
    } else {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
